﻿<template>
  <div>
    <!-- 标题栏 -->
    <NavBar
      :title="$route.meta.title"
      :rightBtn="rightBtn"
      @handleIcon="hanldleRight"
    >
    </NavBar>
    <van-pull-refresh v-model="loading" @refresh="getDataList">
      <van-tree-select
        height="100vh"
        :items="data"
        @click-item="onitemclick"
        :main-active-index.sync="activeIndex"
      />
    </van-pull-refresh>

    <edit-form
      ref="editForm"
      :afterSubmit="() => (loading = false)"
    ></edit-form>
  </div>
</template>

<script>
import { OA_DefForm_GetTreeDataList } from "@/api/OA_Manage/OA_DefForm";
import NavBar from "@/components/NavBar";
import EditForm from "../OA_UserForm/EditForm";

export default {
  components: {
    NavBar,
    EditForm
  },
  mounted() {
    this.getDataList();
  },
  data() {
    return {
      data: [],
      activeIndex: 0,
      loading: false,
      rightBtn: {
        number: 0,
        iconName: []
      }
    };
  },

  methods: {
    getDataList() {
      this.loading = true;
      OA_DefForm_GetTreeDataList({}).then(resJson => {
        this.loading = false;
        this.data = resJson.Data;
        this.expandedKeys = this.data.map(item => {
          return item.key;
        });
      });
    },
    handleEdit(key, title, type, jsonId, jsonVersion, json) {
      this.$refs.editForm.openForm(
        "",
        title,
        type,
        key,
        jsonId,
        jsonVersion,
        json
      );
    },
    onitemclick(data) {
      this.handleEdit(
        data.key,
        data.title,
        data.type,
        data.jsonId,
        data.jsonVersion,
        data.json
      );
    },
    hanldleRight(item) {}
  }
};
</script>

<style lang="less"></style>
